/**
 * Project Name:Micro-Services-Codec-Msgpack
 * File Name   :Main2.java
 * Package Name:com.micro.services.codec.msgpack
 * Date:2015-9-6下午3:21:46
 * Copyright (c) 2015, http://my.oschina.net/httpssl All Rights Reserved.
 *
 */
/**
 *  {{Code Template Comments Files}}
 */

package com.micro.services.codec.msgpack;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;

import org.msgpack.MessagePack;
import org.msgpack.annotation.Message;
import org.msgpack.packer.Packer;
import org.msgpack.unpacker.Unpacker;

/**
 * ClassName:Main2 <br/>
 * Function :TODO ADD FUNCTION. <br/>
 * Reason :TODO ADD REASON. <br/>
 * Date :2015-9-6 下午3:21:46 <br/>
 * 
 * @author :http://my.oschina.net/httpssl
 * @email :491835898@QQ.COM
 * @since :JDK 1.7
 * @see
 */
public class Main2
{
	@Message
	public static class MyMessage
	{
		public String	name;
		public double	version;
	}

	public static void main(String[] args) throws Exception {
		MyMessage src1 = new MyMessage();
		src1.name = "msgpack";
		src1.version = 0.6;
		MyMessage src2 = new MyMessage();
		src2.name = "muga";
		src2.version = 10.0;
		MyMessage src3 = new MyMessage();
		src3.name = "frsyukik";
		src3.version = 1.0;

		MessagePack msgpack = new MessagePack();
		//
		// Serialize
		//
		ByteArrayOutputStream out = new ByteArrayOutputStream();
		Packer packer = msgpack.createPacker(out);
		packer.write(src1);
		packer.write(src2);
		packer.write(src3);
		byte[] bytes = out.toByteArray();

		//
		// DESERIALIZE
		//
		ByteArrayInputStream in = new ByteArrayInputStream(bytes);
		Unpacker unpacker = msgpack.createUnpacker(in);
		MyMessage dst1 = unpacker.read(MyMessage.class);
		MyMessage dst2 = unpacker.read(MyMessage.class);
		MyMessage dst3 = unpacker.read(MyMessage.class);
		System.out.println(dst1);
		System.out.println(dst2);
		System.out.println(dst3);
	}
}
